home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
win
/
pascal
/
ansioem.exe
/
ANSIOEM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-25
|
15KB
|
474 lines
/*---------------------------------------
ANSIOEM.C -- Ansi & Oem Characters.
(c) Robert Digsby, 1992
---------------------------------------*/
#include <windows.h>
#define DIVISIONSX 32
#define DIVISIONSY 8
#define ANSI 0
#define OEM 1
#define STATUS 2
long FAR PASCAL WndProc (HWND, WORD, WORD, LONG) ;
long FAR PASCAL AnsiOemWndProc (HWND, WORD, WORD, LONG) ;
long FAR PASCAL StatusWndProc (HWND, WORD, WORD, LONG) ;
HWND hwndChild [3] ;
char szAnsiOemClass[] = "AnsiOem_Child" ;
char szStatusClass[] = "Status_Child" ;
short cxBlock, cyBlock, cxChar, cyChar ;
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
static char szAppName[] = "AnsiOem" ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
if (!hPrevInstance)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = NULL ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = COLOR_WINDOW + 1 ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
RegisterClass (&wndclass) ;
wndclass.lpfnWndProc = AnsiOemWndProc ;
wndclass.cbWndExtra = sizeof (DWORD) ;
wndclass.hIcon = NULL ;
wndclass.lpszClassName = szAnsiOemClass ;
RegisterClass (&wndclass) ;
wndclass.lpfnWndProc = StatusWndProc ;
wndclass.cbWndExtra = 0 ;
wndclass.hIcon = NULL ;
wndclass.lpszClassName = szStatusClass ;
RegisterClass (&wndclass) ;
}
hwnd = CreateWindow (szAppName, "Ansi & Oem Charaters",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, nCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
{
HDC hdc ;
TEXTMETRIC tm ;
short cxClient, cyClient, cxAnsiPos, cyAnsiPos, cxScreen,
cyScreen, cxSize, cySize ;
switch (message)
{
case WM_CREATE :
hdc = GetDC (hwnd) ;
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT)) ;
GetTextMetrics (hdc, &tm) ;
cxChar = tm.tmAveCharWidth ;
cyChar = tm.tmHeight + tm.tmExternalLeading ;
cxBlock = cxChar * 2 ;
cyBlock = cyChar * 1.3;
ReleaseDC (hwnd, hdc) ;
cxScreen = GetSystemMetrics (SM_CXSCREEN) ;
cyScreen = GetSystemMetrics (SM_CYSCREEN) ;
cxSize = cxBlock * (DIVISIONSX + 2) ;
cySize = cyBlock * ((DIVISIONSY * 2) + 5) ;
MoveWindow (hwnd, (cxScreen - cxSize) / 2,
(cyScreen - cySize) / 2,
cxSize, cySize, FALSE) ;
hwndChild[ANSI] = CreateWindow (szAnsiOemClass, NULL,
WS_CHILDWINDOW | WS_VISIBLE,
0, 0, 0, 0,
hwnd, ANSI,
GetWindowWord (hwnd, GWW_HINSTANCE), NULL) ;
hwndChild[OEM] = CreateWindow (szAnsiOemClass, NULL,
WS_CHILDWINDOW | WS_VISIBLE,
0, 0, 0, 0,
hwnd, OEM,
GetWindowWord (hwnd, GWW_HINSTANCE), NULL) ;
hwndChild[STATUS] = CreateWindow (szStatusClass, NULL,
WS_CHILDWINDOW | WS_VISIBLE,
0, 0, 0, 0,
hwnd, STATUS,
GetWindowWord (hwnd, GWW_HINSTANCE), NULL) ;
return 0 ;
case WM_SIZE :
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
cxAnsiPos = max (cxBlock,
(cxClient - (cxBlock * DIVISIONSX)) / 2) ;
cyAnsiPos = max (cyBlock,
((cyClient - (cyBlock * ((DIVISIONSY * 2) + 2))) / 2)) ;
MoveWindow (hwndChild[ANSI], cxAnsiPos, cyAnsiPos,
cxBlock * DIVISIONSX, cyBlock * DIVISIONSY, TRUE) ;
MoveWindow (hwndChild[OEM],
cxAnsiPos,
cyAnsiPos + (cyBlock * DIVISIONSY) + (cyBlock * 2),
cxBlock * DIVISIONSX, cyBlock * DIVISIONSY, TRUE) ;
MoveWindow (hwndChild[STATUS],
cxAnsiPos,
cyAnsiPos + (cyBlock * DIVISIONSY) + (cyBlock / 2),
cxBlock * DIVISIONSX, cyBlock, TRUE) ;
return 0 ;
case WM_LBUTTONDOWN :
MessageBeep (0) ;
return 0 ;
case WM_SETFOCUS :
SetFocus (hwndChild[ANSI]) ;
return 0 ;
case WM_DESTROY :
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
long FAR PASCAL AnsiOemWndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
{
short x, y, cxPos, cyPos, cPos, xStart, xEnd, yStart, yEnd, n ;
unsigned char sBuffer[1], sConvert[1], sConverted[1] ;
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
HBRUSH hBrush ;
DWORD dwPrevColor, dwPrevText ;
switch (message)
{
case WM_CREATE:
SetWindowWord (hwnd, 0, 0) ;
SetWindowWord (hwnd, 2, 0) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
if (ANSI == GetWindowWord (hwnd, GWW_ID) )
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT)) ;
else
SelectObject (hdc, GetStockObject (OEM_FIXED_FONT)) ;
Rectangle (hdc, 0, 0, cxBlock * DIVISIONSX,
cyBlock * DIVISIONSY) ;
xStart = ps.rcPaint.left / cxBlock ;
xEnd = ps.rcPaint.right / cxBlock ;
yStart = ps.rcPaint.top / cyBlock ;
yEnd = ps.rcPaint.bottom / cyBlock ;
for (x = xStart; x <= xEnd; x++)
{
MoveTo (hdc, x * cxBlock, 0) ;
LineTo (hdc, x * cxBlock, cyBlock * DIVISIONSY) ;
}
for (y = yStart; y <= yEnd; y++)
{
MoveTo (hdc, 0, y * cyBlock) ;
LineTo (hdc, cxBlock * DIVISIONSX, y * cyBlock) ;
}
SetTextAlign (hdc, TA_CENTER) ;
SetTextColor(hdc, GetSysColor (COLOR_WINDOWTEXT)) ;
SetBkColor (hdc, GetSysColor (COLOR_WINDOW)) ;
for (y = yStart; y <= yEnd; y++)
for (x = xStart; x <= xEnd; x++)
{
if (y == GetWindowWord (hwnd, 2) &&
x == GetWindowWord (hwnd, 0))
{
SetRect (&rect, x * cxBlock, y * cyBlock,
(x * cxBlock) + cxBlock,
(y * cyBlock) + cyBlock) ;
if (hwnd == GetFocus())
{
hBrush = CreateSolidBrush
(GetSysColor (COLOR_HIGHLIGHT) ) ;
SetTextColor(hdc,
GetSysColor (COLOR_HIGHLIGHTTEXT)) ;
SetBkColor (hdc,
GetSysColor (COLOR_HIGHLIGHT)) ;
}
else
{
hBrush = CreateSolidBrush
(GetSysColor (COLOR_BTNFACE)) ;
SetBkColor (hdc,
GetSysColor (COLOR_BTNFACE)) ;
}
FillRect (hdc, &rect, hBrush) ;
DeleteObject (hBrush) ;
}
sBuffer[0] = (y * DIVISIONSX) + x ;
TextOut (hdc, (x * cxBlock) + cxChar,
(y * cyBlock) + (cyBlock - cyChar) / 2,
sBuffer, 1) ;
if (y == GetWin